export const localStorageUtil = {
    //设置缓存，过期时间为min = 30*60(秒)=30min
    set(key, val, expire) {
        var exp = expire ? Date.now() + expire * 1000 * 60 : -1;
        localStorage.setItem(key, JSON.stringify({ value: val, expire: exp }));
    },
    get(key) {
        var data = localStorage.getItem(key);
        if (!data) return null;
        var dataObj = JSON.parse(data);
        if (dataObj.expire == -1)
            return dataObj.value;
        if (Date.now() >= dataObj.expire) {
            localStorage.removeItem(key);
            return null;
        } else {
            return dataObj.value;
        }
    }
};